package com.service.Impl;

import com.service.log4jService;
import com.utils.DateUtil;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.Date;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class log4jServiceImpl
  implements log4jService
{
  public void UpdateFilePath()
  {
    Properties properties = new Properties();
    FileInputStream fileInputStream = null;
    try {
      fileInputStream = new FileInputStream(getClass().getResource("/").getFile() + "log4j.properties");
      properties.load(fileInputStream);
    } catch (Exception e) {
      e.printStackTrace();

      if (fileInputStream != null)
        try {
          fileInputStream.close();
        } catch (IOException e1) {
          e1.printStackTrace();
        }
    }
    finally
    {
      if (fileInputStream != null) {
        try {
          fileInputStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    String flume = "log4j.appender.flume.File";
    String value = properties.getProperty(flume);
    System.out.println(value);
    if (!StringUtils.isBlank(value)) {
      value = value.replace(value.split("/")[3], DateUtil.getDateStr(new Date()));
    }
    properties.setProperty(flume, value);
    FileOutputStream fileOutputStream = null;
    try {
      fileOutputStream = new FileOutputStream(getClass().getResource("/").getFile() + "log4j.properties");
      properties.store(fileOutputStream, null);
      fileOutputStream.close();
    } catch (Exception e) {
      e.printStackTrace();

      if (fileOutputStream != null)
        try {
          fileOutputStream.close();
        } catch (Exception e2) {
          e2.printStackTrace();
        }
    }
    finally
    {
      if (fileOutputStream != null)
        try {
          fileOutputStream.close();
        } catch (Exception e2) {
          e2.printStackTrace();
        }
    }
  }
}